package model

import (
	"grpc_tapd_s/mysql"
	"log"
	"time"
)

type Bug struct {
	Id              int
	Bugtype         string
	VerifyTime      time.Time
	Ids             string
	Resolution      string
	Priority        string
	EffortCompleted string
	Status          string
	Fixer           string
	Reporter        string
	Closer          string
	Closed          time.Time
	CustomFieldOne  string
	Created         time.Time
	Description     string
	Title           string
	InProgressTime  time.Time
	Severity        string
}

func (Bug) TableName() string {
	return "tapd_bug"
}
func GetAllBugs(beginTime, endTime string) []Bug {
	var b []Bug
	result := mysql.Db.
		Where("in_progress_time > ? and in_progress_time <= ?", beginTime, endTime).
		Or("closed > ? and closed <= ?", beginTime, endTime).
		Order("id").
		Select("id", "verify_time", "bugtype", "ids", "priority", "effort_completed", "status", "title",
			"fixer", "reporter", "closer", "closed", "custom_field_one", "created", "description", "in_progress_time,severity").
		Find(&b)
	if err := result.Error; err != nil {
		log.Printf("Db.Find err:%v\n", err)
	}
	return b
}
